<?php
if (isset($_GET['file'])) {
    $file = urldecode($_GET['file']);
    $articleDir = 'articles/';
    $articleFile = $articleDir . $file;

    if (!file_exists($articleFile)) {
        echo "文章不存在！";
        exit;
    }

    $articleContent = file_get_contents($articleFile);

    // 提取第一个 <h1> 标签中的内容
    if (preg_match('/<h1>(.*?)<\/h1>/is', $articleContent, $matches)) {
        $title = strip_tags($matches[1]); // 去掉可能存在的HTML标签
    } else {
        $title = "مىكروبىلوگ"; // 如果没有找到 <h1> 标签，使用默认标题
    }
} else {
    echo "无效的请求！";
    exit;
}
?>

<!DOCTYPE html>
<html lang="en">
<head>
<?php include 'head.php'; ?>
    <title><?php echo htmlspecialchars($title); ?>-مىكروبىلوگ</title>
    <style>
        .article-content {
            border: 2px solid blue; /* 蓝色边框 */
            margin: 12px; /* 外边距 */
            padding: 8px; /* 内边距 */
            border-radius: 10px; /* 圆角边框 */
        }
        header {
            background-image: linear-gradient(to right, #eea2a2 0%, #bbc1bf 19%, #57c6e1 42%, #b49fda 79%, #7ac5d8 100%);
            color: #fff;
            padding: 15px 20px;
            text-align: center;
        }
        .button {
            display: inline-block;
            padding: 10px 5px;
            margin: 2px;
            background-color: #5cb85c;
            color: #fff;
            font-size: 0.8em;
            font-weight: bold;
            text-align: center;
            text-decoration: none;
            border: none;
            border-radius: 5px;
            cursor: pointer;
            transition: background-color 0.3s, transform 0.3s;
        }
        @font-face {
            font-family: 'Akaltun';
            src: url('http://kino.akaltun.cn/blog/assets/akaltun1017.woff2') format('woff2');
            font-weight: normal;
            font-style: normal;
        }

        body {
            font-family: 'Akaltun';
            margin: 0;
            padding: 0;
            min-height: 100vh;
            background-image: linear-gradient(to top, #fff1eb 0%, #ace0f9 100%);
        }
    </style>
</head>
<body>
    <header>
        <h1>مەزمۇنى详情</h1>
        <a href="index.php" class="button">首页باشبەت</a>
    </header>
    <main>
        <div class="article-content">
            <?php echo $articleContent; ?>
        </div>
    </main>
    <table border="0" cellspacing="0" cellpadding="0" height="100%" width="100%">
        <tr>
            <td align="center" valign="bottom">
                <footer>
                    <p>&copy;akaltun 2018 مىكرو</p>
                </footer>
            </td>
        </tr>
    </table>
</body>
</html>
